package cn.iocoder.yudao.module.els.dal.mysql.codeGenerator;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.els.controller.admin.codeGenerator.vo.CodeGeneratorPageReqVO;
import cn.iocoder.yudao.module.els.dal.dataobject.codeGenerator.CodeGeneratorDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * 编码生成器 Mapper
 *
 * @author 吕小文
 */
@Mapper
public interface CodeGeneratorMapper extends BaseMapperX<CodeGeneratorDO> {

    default PageResult<CodeGeneratorDO> selectPage(CodeGeneratorPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CodeGeneratorDO>()
                .likeIfPresent(CodeGeneratorDO::getGeneratorName, reqVO.getGeneratorName())
                .eqIfPresent(CodeGeneratorDO::getCodeType, reqVO.getCodeType())
                .eqIfPresent(CodeGeneratorDO::getCodeLength, reqVO.getCodeLength())
                .eqIfPresent(CodeGeneratorDO::getSerialLength, reqVO.getSerialLength())
                .eqIfPresent(CodeGeneratorDO::getCodeSample, reqVO.getCodeSample())
                .betweenIfPresent(CodeGeneratorDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CodeGeneratorDO::getId));
    }

    default CodeGeneratorDO getByCodeType(String codeType){
        return selectOne(new LambdaQueryWrapper<CodeGeneratorDO>()
                .eq(CodeGeneratorDO::getCodeType,codeType)
                .last("limit 1")
        );
    }



}